package com.gcxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gcxy.conf.result.R;
import com.gcxy.entity.City;
import com.gcxy.mapper.CityMapper;
import com.gcxy.service.CityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 基础表-省市区 服务实现类
 * </p>
 *
 * @author jiang
 * @since 2023-12-21
 */
@Service
public class CityServiceImpl extends ServiceImpl<CityMapper, City> implements CityService {

    @Override
    public R getProvince(City city) {
        //查询条件；模糊查询所有省份
        LambdaQueryWrapper<City> lqw = new LambdaQueryWrapper<>();
        lqw.like(null != city.getName(),City::getName,city.getName())
                .eq(City::getLevel,1);
        List<City> cityList = this.baseMapper.selectList(lqw);
        return R.Success(cityList);
    }

    @Override
    public R getCity(City city) {
        //查询条件；模糊查询所有市
        LambdaQueryWrapper<City> lqw = new LambdaQueryWrapper<>();
        lqw.like(null != city.getName(),City::getName,city.getName())
                .eq(null!=city.getParentId(),City::getParentId,city.getParentId())
                .eq(City::getLevel,2);
        List<City> cityList = this.baseMapper.selectList(lqw);
        return R.Success(cityList);
    }

    @Override
    public R getCounty(City city) {
        //查询条件；模糊查询所有区县
        LambdaQueryWrapper<City> lqw = new LambdaQueryWrapper<>();
        lqw.like(null != city.getName(),City::getName,city.getName())
                .eq(null!=city.getParentId(),City::getParentId,city.getParentId())
                .eq(City::getLevel,3);
        List<City> cityList = this.baseMapper.selectList(lqw);
        return R.Success(cityList);
    }
}
